﻿package mortal.game.view.copy.groupCopy.view
{
    import Message.DB.Tables.*;
    import Message.Public.*;
    import com.greensock.layout.*;
    import com.mui.controls.*;
    import extend.language.*;
    import flash.events.*;
    import mortal.common.*;
    import mortal.common.global.*;
    import mortal.component.gconst.*;
    import mortal.component.window.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.manager.msgTip.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.view.common.*;
    import mortal.game.view.group.*;
    import mortal.mvc.core.*;
    import mortal.mvc.interfaces.*;

    public class GroupCopySettingWin extends SmallWindow
    {
        private var _nameTextBox:GTextInput;
        private var _psswordTextBox:GTextInput;
        private var _combatTextBox:GTextInput;
        private var _btnOk:GButton;
        private var _btnCancel:GButton;
        private var _tcopy:TCopy;
        private static var _instance:GroupCopySettingWin;

        public function GroupCopySettingWin(param1:ILayer = null)
        {
            if (_instance != null)
            {
                throw new Error(" GroupCopySettingWin 单例 ");
            }
            this.setSize(300, 204);
            this.title = Language.getString(35239);
            this.layer = LayerManager.topLayer;
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            paddingBottom = 38;
            this.pushUIToDisposeVec(UIFactory.gTextField(Language.getString(35240), 63, 51, 70, 20, this));
            this.pushUIToDisposeVec(UIFactory.gTextField(Language.getString(35241), 63, 91, 70, 20, this));
            this.pushUIToDisposeVec(UIFactory.gTextField(Language.getString(35242), 63, 131, 70, 20, this));
            this._nameTextBox = UIFactory.gTextInput(130, 51, 120, 22, this);
            this._nameTextBox.textField.wordWrap = true;
            this._nameTextBox.maxChars = 50;
            this._nameTextBox.maxChars = 7;
            this._nameTextBox.restrict = "一-龥 -~·-=【】；‘、，。、.~！@#￥%……&*（）——+{}：’“”|《》？/*.‘’";
            this._nameTextBox.textField.filters = [FilterConst.glowFilter];
            this._nameTextBox.configEventListener(FocusEvent.FOCUS_OUT, this.changeTeamName);
            this._psswordTextBox = UIFactory.gTextInput(130, 91, 120, 22, this);
            this._psswordTextBox.textField.wordWrap = true;
            this._psswordTextBox.textField.displayAsPassword = true;
            this._psswordTextBox.maxChars = 8;
            this._psswordTextBox.restrict = "0-9a-zA-Z";
            this._psswordTextBox.textField.filters = [FilterConst.glowFilter];
            this._combatTextBox = UIFactory.gTextInput(130, 131, 120, 22, this);
            this._combatTextBox.textField.wordWrap = true;
            this._combatTextBox.maxChars = 8;
            this._combatTextBox.restrict = "0-9";
            this._combatTextBox.textField.filters = [FilterConst.glowFilter];
            this._btnOk = UIFactory.gButton(Language.getString(35237), 65, 175, 60, 30, this);
            this._btnOk.configEventListener(MouseEvent.CLICK, this.setGroupCopy);
            this._btnCancel = UIFactory.gButton(Language.getString(35238), 185, 175, 60, 30, this);
            this._btnCancel.configEventListener(MouseEvent.CLICK, this.cancel);
            var _loc_1:* = GlobalStyle.textFormatHuang;
            _loc_1.align = AlignMode.CENTER;
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            this._btnOk.dispose(param1);
            this._btnOk = null;
            this._btnCancel.dispose(param1);
            this._btnCancel = null;
            this._nameTextBox.dispose(param1);
            this._nameTextBox = null;
            this._psswordTextBox.dispose(param1);
            this._psswordTextBox = null;
            this._combatTextBox.dispose(param1);
            this._combatTextBox = null;
            super.disposeImpl(param1);
            return;
        }// end function

        private function setGroupCopy(event:MouseEvent) : void
        {
            var _loc_2:* = new SGroupSetting();
            _loc_2.groupId = new SEntityId();
            _loc_2.name = this._nameTextBox.text;
            _loc_2.password = this._psswordTextBox.text;
            _loc_2.combatLimit = int(this._combatTextBox.text);
            Dispatcher.dispatchEvent(new DataEvent(EventName.GroupSetting, _loc_2));
            return;
        }// end function

        private function changeTeamName(event:FocusEvent) : void
        {
            if (this._nameTextBox.text == Cache.instance.group.groupName)
            {
                return;
            }
            if (Cache.instance.role.entityInfo.level < GameDefConfig.instance.getSystemOpenLevel(90))
            {
                this._nameTextBox.text = Cache.instance.group.groupName;
                return MsgManager.showRollTipsMsg(Language.getStringByParam(35243, GameDefConfig.instance.getSystemOpenLevel(90)), MsgRollTipsType.msgRollTips3);
            }
            return;
        }// end function

        private function cancel(event:MouseEvent) : void
        {
            this.hide();
            return;
        }// end function

        public function set data(param1:TCopy) : void
        {
            var _loc_2:* = Cache.instance.group;
            this._nameTextBox.text = _loc_2.groupName;
            this._combatTextBox.text = _loc_2.combat >= 0 ? (_loc_2.combat.toString()) : (param1.combat.toString());
            this._psswordTextBox.text = _loc_2.passWord;
            return;
        }// end function

        public static function get isViewShow() : Boolean
        {
            return _instance && !_instance.isHide;
        }// end function

        public static function get instance() : GroupCopySettingWin
        {
            if (_instance == null)
            {
                _instance = new GroupCopySettingWin;
            }
            return _instance;
        }// end function

    }
}
